package com.pronosticnews.server.services.images;

import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.pronosticnews.server.domain.dao.ImageDao;
import com.pronosticnews.server.domain.model.Image;

import fr.ysa.persistence.DaoException;
import fr.ysa.persistence.requetes.ConfigRequetes;
import fr.ysa.services.ServiceException;

@Service("imageService")
@Transactional
public class ImageServiceImpl implements ImageService {

	@Autowired
	ImageDao imageDao;

	@Override
	public Integer compter(ConfigRequetes config) throws ServiceException {
		try {
			return imageDao.compter(config);
		} catch (DaoException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	@Override
	public Image modifier(Image image) throws ServiceException {
		try {
			return imageDao.modifier(image);
		} catch (DaoException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	@Override
	public Collection<Image> sauvegarder(Collection<Image> entities)
			throws ServiceException {
		try {
			return imageDao.sauvegarder(entities);
		} catch (DaoException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	@Override
	public Image sauvegarder(Image image) throws ServiceException {
		try {
			return imageDao.sauvegarder(image);
		} catch (DaoException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	@Override
	public void supprimer(Collection<Image> entities) throws ServiceException {
		try {
			imageDao.supprimer(entities);
		} catch (DaoException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	@Override
	public void supprimer(Image image) throws ServiceException {
		try {
			imageDao.supprimer(image);
		} catch (DaoException e) {
			throw new ServiceException(e.getMessage());
		}
	}

	@Override
	public List<Image> trouver(ConfigRequetes config) throws ServiceException {
		try {
			return imageDao.trouver(config);
		} catch (DaoException e) {
			throw new ServiceException(e.getMessage());
		}
	}

}
